<template>
<div class="d1">
  <div class="left col-sm-8">
    <criteria-paged :model="model">
      <criteria partial='criteria' @condition-changed='search'>
        <div novalidate class="form-inline" partial>
          <div class="form-group">
            <label for="f_state">状态</label>
            <v-select :value.sync="model.f_state" v-model="model.f_state" :options='$parent.$parent.f_state' placeholder='请选择' close-on-select clear-button condition="f_state ='{}'"></v-select>
          </div>
          <div class="form-group">
            <label for="f_receiver">申请人:</label>
            <v-select :value.sync="model.f_receiver" v-model="model.f_receiver" :options='$parent.$parent.f_receiver' placeholder='请选择' close-on-select clear-button></v-select>
          </div>
          <button class="btn btn-primary" id="selectbtn" @click="search()">查询</button>
          <button class="btn btn-info" @click="$parent.$parent.setmodal(row)">表具管理</button>
          </button>
          <export-excel :data="{orderitem: 'id', condition: '1=1'}" :field="{xmlPath: '营收/handplan.hbm.xml'}" sqlurl="rs/excel/userHPDetail">导出excel</export-excel>
        </div>
      </criteria>
      <data-grid :model="model" partial='list' v-ref:grid class="data-grid" is-fixed='false' style="overflow-x:auto">
        <template partial='head'>
          <tr class="title">
            <th>
              <input type='checkbox' name='checkboxinput'
                v-model='$parent.$parent.$parent.selectArr1'
               v-on:click='$parent.$parent.$parent.selectAll1(model.rows)'>
            </th>
            <th><nobr>序号</nobr></th>
            <th><nobr>表号</nobr></th>
            <th><nobr>气表品牌</nobr></th>
            <th><nobr>气表型号</nobr></th>
            <th><nobr>状态</nobr></th>
            <th><nobr>安装地址</nobr></th>
            <th><nobr>小区</nobr></th>
            <th><nobr>电话</nobr></th>
            <th><nobr>领取人</nobr></th>
            <th><nobr>领取时间</nobr></th>
            <th><nobr>安装时间</nobr></th>
            <th><nobr>登记人</nobr></th>
            <th><nobr>操作</nobr></th>

          </tr>
        </template>
        <template partial='body'>
          <tr @dblclick="$parent.$parent.$parent.showmodal(row)" class="t3">
            <td>
              <input type='checkbox' name='checkboxinput' @click="$parent.$parent.$parent.selectOne(row)"
             v-model='$parent.$parent.$parent.selectArr' value="{{row.f_meternumber}}">
            </td>
            <td><nobr>{{$index+1}}</nobr></td>
            <td><nobr>{{row.f_meternumber}}</nobr></td>
            <td><nobr>{{row.f_gaswatchbrand}}</nobr></td>
            <td><nobr>{{row.f_metertype}}</nobr>  </td>
            <td><nobr>{{row.f_state}}</nobr></td>
            <td><nobr>{{row.f_address}}</nobr></td>
            <td><nobr>{{row.f_districtname}}</nobr></td>
            <td><nobr>{{row.f_phone}}</nobr></td>
            <td><nobr>{{row.f_receiver}}</nobr></td>
            <td><nobr>{{row.f_receiverdate}}</nobr></td>
            <td><nobr>{{row.f_sinstalldate}}</nobr></td>
            <td><nobr>{{row.f_operator}}</nobr></td>
            <td>
              <button class="btn btn-info" v-show='isSelected(row)'  @click="$parent.$parent.$parent.hh(row) "@dblclick.capture="$parent.$parent.$parent.hh1(row)">查看</button>

            </td>
          </tr>
        </template>
        <template partial='foot'>
          <td class="t1">
            <button class="btn btn-primary" @click="$parent.$parent.$parent.receive(this.selectArr,this.model)">领取</button>
          </td>
          <td class="t1">
            <button class="btn btn-warning" @click="$parent.$parent.$parent.remove(this.selectArr,this.model)">退回</button>
          </td>
        </template>
      </data-grid>
    </criteria-paged>

    <card-modal :arr='row' :show="see" @reply="s"></card-modal>
    <meter-message :show="seen" @replys="b"></meter-message>
  </div>
  <div class="d2 col-sm-4">
    <card :arr='model'></card>
  </div>

</div>
</template>

<script>
import {
PagedList} from 'vue-client'
import * as Util from '../../Util'
import AppData from '../../../stores/AppData'
export default {
  title: '表具管理',
  data () {
    return {
      model: new PagedList('rs/sql/singleTable_OrderBy', 10, {
        items: "'*'",
        tablename: "'t_gasmanagement'",
        orderitem: "'id'",
        select: ''
      }),
      row: {},
      // },
      f_state: [{
          label: '全部',
          value: ''
        },
        {
          label: '已安装',
          value: '已安装'
        },
        {
          label: '已领取',
          value: '已领取'
        },
        {
          label: '未领取',
          value: '未领取'
        },
        {
          label: '已损坏',
          value: '已损坏'
        }
      ],
      selectArr: [],
      selectArr2: [],
      // 存储需要修改的数组
      selectArr1: '',
      show: false,
      see: false,
      seen: false,
      models: {
        f_state: '',
        f_receiver: '',
        f_userid: '',
        f_meternumber: '',
        f_operator: '',
        f_operatordate: ''
      },
      model1: {
        change: '000000'
      },
      model2: {
        f_meternumber: '000000'
      },
      select: '',
      jl: ''
    }
  },

  computed: {
    f_receiver() {
      return [{label: '全部', value: ''}, ...AppData.getParam('申请人')]
    }
  },
  methods: {
    selectAll1: function (data) {
      console.log(this.selectArr1)
      if (!this.selectArr1) {
        this.selectArr = []
        this.selectArr2 = []
        data.forEach((item) => {
          this.selectArr.push(item.f_meternumber)
          this.selectArr2.push(item.f_state)
        })
      } else {
        this.selectArr = []
        this.selectArr2 = []
      }
    },
    selectOne (data) {
      if (this.selectArr.includes(data.f_meternumber)) {
        this.selectArr2.$remove(data.f_state)
        this.selectArr.$remove(data.f_meternumber)
      } else {
        this.selectArr2.push(data.f_state)
        this.selectArr.push(data.f_meternumber)
      }
    },
    receive (model) {
      this.model2.f_receiverdate =Util.toStandardDateString()
      console.log('shijian======================' + this.model2.f_receiverdate)
      this.model2.f_meternumber = this.selectArr
      var j = 0
      for (var i = 0; i < this.selectArr2.length; i++) {
        if (this.selectArr2[i] === '已领取') {
          window.alert('存在已领取的表具')
          j = 1
          this.selectArr1 = false
          this.selectArr = []
          return
        }
      }
      if (j === 0) {
        this.model2.receiver = this.model.model.f_receiver[0]
        this.model1.f_receiver = this.model.model.f_receiver[0]
        this.model1.f_operatordate =Util.toStandardDateString()
        this.model1.f_changestatus = '已领取'
        this.$post('rs/logic/savemeter', {
          data: {
            table1: 'table1',
            model2: this.model2,
            table2: 't_gasmanagenumber',
            model1: this.model1
          }
        })
        this.selectArr1 = false
        this.selectArr = []
      }
    },
    remove (model) {
      var k = 0
      for (var i = 0; i < this.selectArr2.length; i++) {
        if (this.selectArr2[i] === '未领取') {
          window.alert('存在未领取的表具')
          k = 1
          return
        }
      }
      if (k === 0) {
        this.model2.f_meternumber = this.selectArr
        this.model1.f_receiver = this.model.model.f_receiver[0]
        this.model1.f_changestatus = '已退回'
        this.model1.f_operatordate =Util.toStandardDateString()
        this.$post('rs/logic/removemeter', {
          data: {
            table1: 'table1',
            model2: this.model2,
            table2: 't_gasmanagenumber',
            model1: this.model1
          }
        })
        this.selectArr1 = false
        this.selectArr = []
      }
    },
    open (row) {},
    showmodal (row) {
      this.row = row
      console.log(1111111111111111111111111111)
      this.see = true
    },
    hh (row) {
      console.log(1111111111111111111111111111)
      this.row = row
      this.see = true
    },
    hh1 (row) {
      console.log(22222222222222222222222222222222)
      this.row = row
      this.see = true
    },
    setmodal (row) {
      console.log(222)
      this.seen = true
    },
    s(t) {
      this.see = t
    },
    b(b) {
      this.seen = b
    }
  }
}
</script>
<style>
tr.title {
  background-color: #6666ff;
}







/*div.d1 {
  background-color: #999999;
}*/


/*td.t1 {
  background-color: #999999;
}*/
</style>
